// packageC/pages/package/gonzhuangronqiguanli/package_improve/add_improve/add_improve.js
const mybehavior = require("../../../../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    fs_upload_url: "https://logisticsengineering.gree.com/container_manage_api/container_manage",
    baseUrl: "https://logisticsengineering.gree.com/container_manage_api/advise_manage",
    img_required: false,
    options1: [],
    choose_img_btn_disabled: false,
    data_list: [],
    company: "",
    manager: "",
    material_type: "",
    material_code: "",
    material_name: "",
    problem_description: "",
    problem_files: [],
    advice: "",
    advice_files: [],
    workshop_line: "",
    meet_standard: ""



  },
  // 获取物料类别数据信息
  getMaterialnDatas() {
    let url = this.data.baseUrl + "/query_material_type"
    let data = {
      company: this.data.company
    }
    this.post(url, data).then(res => {
      console.log("获取物料类别数据信息", res.data)
      let arr = []
      for (let i in res.data) {
        arr.push(res.data[i].material_type)
      }
      if (res.code == 20000) {
        this.setData({
          options1: arr,
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  onChange(event) {

    this.setData({
      meet_standard: event.detail,
    });
    let self = this
    if (event.detail == "no") {
      wx.showModal({
        title: '是否进行监督举报',
        content: '',
        complete: (res) => {
          if (res.cancel) {
            self.setData({
              meet_standard: event.detail,
            })
          }
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/containers_inspection/containers_inspection',

            })
          }
        }
      })
    }
  },
  // 显示详情
  showDetail(e) {
    let row = e.currentTarget.dataset.row_data
    console.log(row);
    let data = {
      material_code: row.content.infoData.material_code,
      use_in: row.use_in,
    }
    wx.navigateTo({
      url: '/packageB/pages/package/pfep/standard_query/supplier_modify_standard/supplier_modify_standard',
      success(res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', data)

      }
    })
  },
  // 获取--待办--数据
  getStandardDatas() {
    let query_cond = {
      "content.infoData.material_code": { "$regex": this.data.material_code },
      use_in: { "$regex": this.data.use_in }
    }
    let url = "https://logisticsengineering.gree.com/pfep2_api/standard_doc_store_manage/query_standard_doc_store"
    let data = {
      page: 1,
      page_size: 99999,
      query_cond: query_cond,
      tb_key: ""
    }
    this.post(url, data).then(res => {
      console.log("物料编码模板", res.data.results);

      if (res.code == 20000) {

        this.setData({
          data_list: res.data.results,

        })

      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 扫描
  scan1(e) {
    let key = e.currentTarget.dataset.key
    console.log(key);
    const self = this;
    wx.scanCode().then((res) => {
      const label_code = res.result;
      wx.showLoading({
        title: "loading"
      })
      console.log(label_code);
      setTimeout(function () {
        wx.hideLoading()
        self.setData({
          [key]: label_code,
        })
        if (key == "material_code") {
          self.getMaterialCodeDatas1()
        } else {
          self.onRadioChange()
        }
      }, 500)

    }).catch(err => {
      console.log(err);
    });
  },
  // 下拉选择
  getPickerVlaue(e) {
    let key = e.target.id
    this.setData({
      [key]: e.detail

    })
  },
  // 上传照片
  getUploaderVlaue(e) {
    let key = e.target.id
    this.setData({
      [key]: e.detail
    })
  },
  // 提交
  submit() {
    let url = this.data.baseUrl + "/advice_submit"
    let data = {
      material_type: this.data.material_type,
      material_code: this.data.material_code,
      material_name: this.data.material_name,
      problem_description: this.data.problem_description,
      problem_files: this.data.problem_files,
      advice: this.data.advice,
      advice_files: this.data.advice_files,
      workshop_line: this.data.workshop_line,
      meet_standard: this.data.meet_standard,
    }
    console.log(data);
    this.post(url, data).then(res => {

      if (res.code == 20000) {
        wx.showToast({
          title: res.msg,
          icon: 'success'
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      company: wx.getStorageSync('company'),
      manager: wx.getStorageSync('department'),
    })
    this.getMaterialnDatas()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})